var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, o, n) {
    var c, a = arguments.length, i = a < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n); else for (var s = t.length - 1; 0 <= s; s--) (c = t[s]) && (i = (a < 3 ? c(i) : 3 < a ? c(e, o, i) : c(e, o)) || i);
    return 3 < a && i && Object.defineProperty(e, o, i), i;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"), s = e("AudioManager"), c = e("GameData"), l = e("EggsManager"), d = e("DataManager"), u = e("LoadManager"), p = e("UIManager"), h = e("WebManager"), f = cc._decorator, g = f.ccclass, m = f.property, y = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.target = null, t.btnNode = null, t.touchArea = null, t.shadow = null, t.touchId = null, 
        t.isCheck = !1, t.idx = 8, t.pos = cc.v2(), t;
    }
    return i(t, e), t.prototype.onEnable = function() {
        -1 == l.default.getInstance().checkEggPerson(this.idx) && this.addTouchEvent();
    }, t.prototype.onDisable = function() {
        this.removeTouchEvent();
    }, t.prototype.onClick = function() {
        var e, o = this;
        -1 == l.default.getInstance().checkEggPerson(this.idx) && (h.default.getInstance().sentLog("获得皮肤彩蛋id:" + this.idx), 
        s.default.getInstance().playAudio("皮肤出现"), this.shadow.parent = cc.Canvas.instance.node, 
        this.shadow.active = !0, e = new cc.Node().addComponent(sp.Skeleton), u.default.getInstance().loadRes({
            url: "skeleton/皮肤" + r.G.eggPersonModelList[this.idx].m + "/skeleton",
            type: sp.SkeletonData
        }).then(function(t) {
            e.skeletonData = t, e.node.parent = cc.Canvas.instance.node, e.node.scale = 1, e.node.zIndex = 1, 
            e.setAnimation(0, "animation", !1), o.scheduleOnce(function() {
                s.default.getInstance().playAudio("彩蛋皮肤" + r.G.eggPersonModelList[o.idx].m, 1);
            }, 3.5), e.setCompleteListener(function() {
                p.default.getInstance().loadPopPnl("egg_reward", {
                    type: r.RewardType.SKIN,
                    idx: o.idx
                }, function() {
                    o.shadow.parent = o.node, o.shadow.active = !1, e.setCompleteListener(null), e.node.destroy(), 
                    o.target.setPosition(o.pos);
                });
            });
        }), this.removeTouchEvent(), l.default.getInstance().updateEggPerson(this.idx), 
        c.GD.personIdx = -1 - this.idx, c.GD.eggsHintState = 1, d.default.getInstance().save());
    }, t.prototype.start = function() {
        this.pos = this.target.getPosition();
    }, t.prototype.addTouchEvent = function() {
        this.touchArea.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.removeTouchEvent = function() {
        this.touchArea.off(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), this.touchArea.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
        this.touchArea.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
    }, t.prototype.touchStartHandler = function(t) {
        null == this.touchId && (this.touchId = t.getID()), this.touchId == t.getID() && (t = t.getLocation(), 
        t = this.target.convertToNodeSpaceAR(t), Math.abs(t.x) <= this.target.width / 2 && Math.abs(t.y) <= this.target.height / 2 && (this.isCheck = !0));
    }, t.prototype.touchMoveHandler = function(t) {
        cc.log(t.getID()), this.touchId == t.getID() && this.isCheck && this.target.setPosition(this.target.parent.convertToNodeSpaceAR(t.getLocation()));
    }, t.prototype.touchEndHandler = function(t) {
        var e;
        this.touchId = null, this.isCheck ? this.isCheck = !1 : (e = t.getLocation(), e = this.btnNode.convertToNodeSpaceAR(e), 
        Math.abs(e.x) <= this.btnNode.width / 2 && Math.abs(e.y) <= this.btnNode.height / 2 && (cc.tween(this.btnNode).to(.1, {
            scale: 1.1
        }).to(.1, {
            scale: 1
        }).start(), this.onClick(t)));
    }, a([ m(cc.Node) ], t.prototype, "target", void 0), a([ m(cc.Node) ], t.prototype, "btnNode", void 0), 
    a([ m(cc.Node) ], t.prototype, "touchArea", void 0), a([ m(cc.Node) ], t.prototype, "shadow", void 0), 
    a([ g ], t);
}(cc.Component);

n.default = y;